package com.liaoban.app.ui.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.liaoban.app.R;
import com.liaoban.app.api.type.event.ShareTixianSucEvent;
import com.liaoban.app.api.type.event.TixianSucEvent;
import com.liaoban.app.biz.CommonBiz;
import com.liaoban.app.constants.ExtraParam;
import com.liaoban.app.helper.ToastHelper;
import com.liaoban.app.ui.base.BaseToolbarActivity;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by ybc on 2018/8/9 0009.
 * 提现
 */
public class WithDrawActivity extends BaseToolbarActivity {
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.tv_name)
    TextView tv_name;
    @BindView(R.id.tv_money)
    TextView tv_money;
    @BindView(R.id.tv_total_money)
    TextView tv_total_money;

    public static int TYPE_TIXIAN = 1; //普通提现
    public static int TYPE_TIXIAN_SHARE = 2;//分享提现

    private int mType;
    private String mMoney;
    private String mName;

    public static Intent newIntent(Context context, int type, String money, String name) {
        Intent intent = new Intent(context, WithDrawActivity.class);
        intent.putExtra(ExtraParam.TYPE, type);
        intent.putExtra(ExtraParam.NAME, name);
        intent.putExtra(ExtraParam.MONEY, money);
        return intent;
    }

    @Override
    protected String getNewTitle() {
        return "提现";
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_with_draw;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        mType = getIntent().getIntExtra(ExtraParam.TYPE, 0);
        mMoney = getIntent().getStringExtra(ExtraParam.MONEY);
        mName = getIntent().getStringExtra(ExtraParam.NAME);
        tvRight.setText("明细");
        tvRight.setVisibility(View.VISIBLE);
        tv_name.setText(mName);
        tv_money.setText(mMoney);
        tv_total_money.setText("可提现余额¥" + mMoney + ",");
    }

    @OnClick(R.id.tv_right)
    public void right() {
        startActivity(new Intent(this, EarnListActivity.class));
    }

    @OnClick(R.id.tv_submit)
    public void submit() {
        if (TYPE_TIXIAN == mType) { //普通提现
            showRunningDialog(R.string.committing);
            startTask(CommonBiz.getInstance().tixian(), objectBaseResponse -> {
                ToastHelper.show(this, objectBaseResponse.msg);
                if (1 == objectBaseResponse.code) {
                    EventBus.getDefault().post(new TixianSucEvent());
                    finish();
                }
            });
        } else if (TYPE_TIXIAN_SHARE == mType) { //分享提现
            showRunningDialog(R.string.committing);
            startTask(CommonBiz.getInstance().shareTixian(), objectBaseResponse -> {
                ToastHelper.show(this, objectBaseResponse.msg);
                //if (1 == objectBaseResponse.code) {
                EventBus.getDefault().post(new ShareTixianSucEvent());
                finish();
                //}
            });
        }
    }
}
